package com.jprocms.module.cms.convert.sitedetailtpl;

import com.jprocms.module.cms.api.dto.SiteContentDefTplDto;
import com.jprocms.module.cms.api.vo.SiteContentDefTplVO;
import com.jprocms.module.cms.dal.dataobject.sitedetailtpl.SiteDetailTplDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import org.springframework.util.StringUtils;

import java.util.List;

import static com.jprocms.module.cms.constant.CmsSysConstants.SUFFIX;

/**
 * 站点各个发布平台的内容详情默认模板 Convert
 *
 * @author jprocms
 */
@Mapper
public interface SiteDetailTplConvert {

    SiteDetailTplConvert INSTANCE = Mappers.getMapper(SiteDetailTplConvert.class);

    SiteDetailTplDO convert(SiteContentDefTplDto bean);

    SiteContentDefTplVO convert(SiteDetailTplDO bean);

    List<SiteContentDefTplVO> convert(List<SiteDetailTplDO> beans);

    default List<SiteContentDefTplVO> joinSuffixConvert(List<SiteDetailTplDO> beans) {
        List<SiteContentDefTplVO> vos = convert(beans);
        for (SiteContentDefTplVO vo : vos) {
            String detailTpl = vo.getDetailTpl();
            if (StringUtils.hasText(detailTpl)) {
                detailTpl = detailTpl + SUFFIX;
            }
            vo.setDetailTpl(detailTpl);
        }
        return vos;
    }

}
